<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>

<script type="text/javascript">
	//文本框
	var editor;
	$(function() {
		editor = $("#seckillcontent")
				.xheditor(
						{
							tools : 'Removeformat,Fontface,FontSize,Bold,Italic,Underline,Strikethrough,FontColor,BackColor,Align,Emot',
							skin : 'default',
							showBlocktag : false,//段落标签
							internalScript : false,
							internalStyle : false,
							width : 580,
							height : 200,
							fullscreen : false,
							forcePtag : true,
							cleanPaste : 1,
							upMultiple : 1,
							html5Upload : false,
							upImgUrl : "",
							upImgExt : 'jpg,jpeg,gif,png',
							onUpload : insertUpload
						//指定回调函数
						});
		//	$("#seckillcontent").focus();
		
	});
	$(function(){
		$("#seckillDateSec").load("seckillSec.cms");

		/* var nowDate = new Date();
		myDate.toLocaleDateString() */
	});
	//添加秒杀时间
	function addSecKillTimeButton() {

		$("#seckill_item").append(
				"<div class='seckillTime'><div>----------------------------------------------------</div><a onclick='javascript:moveseckillTime(this);' style=\"cursor: pointer;\">[删除]</a><div><input type='text' id='startTime' value='" + $("#calendar_start_time").val()
				+ "'>开始时间</div><div><input type='text' id='endTime' value='" + $("#calendar_end_time").val()
				+ "'>结束时间</div><div><input type='text' id='number' value='" + $("#count").val() + "'>秒杀数量</div></div>");
		$("#calendar_start_time").val("");
		$("#calendar_end_time").val("");
		$("#count").val("");
	}
	//保存新的秒杀活动
	function releaseSeckill(){
		var isDaily =false;
		if($("#dailyCheck").attr("checked"))
			isDaily=true;
			
		var secKillTimeList = new Array();
		$(".seckillTime").each(function() {
			/*  alert($(this).find("#startTime").val());
			alert($(this).find("#endTime").val());
			alert($(this).find("#number").val());  */
			secKillTimeList.push({
				"startTime":$(this).find("#startTime").val(),
				"endTime":$(this).find("#endTime").val(),
				"count":$(this).find("#number").val(),
				"customCount":$(this).find("#number").val()
			});
		});
		$.post("submitSeckill.cms",{
			title:$("#title").val(), 
			buttonName:$("#buttonName").val(),
			seckillcontent:$("#seckillcontent").val(),
			secKillTimeList : $.toJSON(secKillTimeList),
			validateMsg:$("#validateMsg").val(),
			picUrl:	$("#seckillPicUrl").val(),
			seckillType:$("#seckill_type_query").val(),
			startDate:$("#calendar_start_date").val(),
			endDate:$("#calendar_end_date").val(),
			isDaily:isDaily
		},function(data){
			if(data=='success'){
				$("#content_detail").load("seckillList.cms");
			}
		});	
	}
	//上传图片
	function seckillUploadImg(){
		var filepath=$("#uploadImgseckill").val(); 
		var extStart=filepath.lastIndexOf("."); 
		var ext=filepath.substring(extStart,filepath.length).toUpperCase(); 
		if(ext!=".PNG"&&ext!=".JPG"&&ext!=".JPEG"&&ext!=".GIF"){ 
			alert("图片限于png,jpeg,jpg,gif格式"); 
			return ; 
		}
		$("#seckill_upload_img_form").ajaxSubmit({
			dataType : 'json',
			cache : false,
			success : function(data) {
				$("#seckillPicUrl").val(data.pictureUrl);
				 if(data.pictureUrl!=""){
					 alert("上传图片成功");
				}else{
					alert("上传图片失败");
					
				}
				
			},
			error : function(err) {
				alert(err);
			}
		});
		return false;
	}
	//是否日常活动
	function isDailySeckill(){
		 if($("#dailyCheck").attr("checked")){
			$("#seckillDate").show();
			$("#seckillDateSec").load("seckillDateSec.cms");
			$("#seckill_item").empty();
		 }
		 else{
			 $("#seckillDate").hide();
			 $("#seckillDateSec").load("seckillSec.cms");
			 $("#seckill_item").empty();
		 }
	}
</script>
<strong style="font-size: 15px; color: red;">添加活动页面</strong>

<table border="1">
	<tr>
		<td>活动类型：</td>
		<td><select id="seckill_type_query">
				<option value="01">精彩活动</option>
				<option value="02">试手气</option>
		</select> <input type="checkbox" name="dailyCheck" onclick="isDailySeckill()"
			id="dailyCheck">日常活动</td>
	</tr>

	<tr>
		<td>秒杀标题：</td>
		<td><input type="text" name="title" id="title" />
		</td>
	</tr>
	<tr>
		<td>按键名称：</td>
		<td><input type="text" name="buttonName" id="buttonName" />
		</td>
	</tr>
	<tr>
		<td>活动内容：</td>
		<td><textarea id="seckillcontent" name="seckillcontent"></textarea>
		</td>
	</tr>
	<tr>
		<td>图片：<input type="hidden" id="seckillPicUrl"
			name="seckillPicUrl" />
		</td>
		<td>
			<div class="type-file-box">
				<form id="seckill_upload_img_form" enctype="multipart/form-data"
					method="post" action="seckillUploadImg.cms">
					<input type="file" id="uploadImgseckill" name="uploadImgseckill"
						onchange="seckillUploadImg();return false;">
				</form>
			</div>
		</td>
	</tr>
	<tr id="seckillDate" style="display: none">
		<td><font color="red">[日常活动]</font>秒杀日期：</td>
		<td>
			<div style="top: 300px; left: 220px;">
				<div class="h_timeCreate_Input02">
					<%
						java.text.DateFormat f = new java.text.SimpleDateFormat(
								"yyyy-MM-dd");
						String nowDate = f.format(new java.util.Date());
					%>
					开始日期<input
						onClick="WdatePicker({el:'calendar_start_date',dateFmt:'yyyy-MM-dd'});"
						type="text" id="calendar_start_date" name="startDate"
						value="<%=nowDate%>" />
				</div>
				<div class="h_timeCreate_Input02">
					结束日期<input
						onClick="WdatePicker({el:'calendar_end_date',dateFmt:'yyyy-MM-dd'});"
						type="text" id="calendar_end_date" name="endDate"
						value="<%=nowDate%>" />
				</div>
			</div></td>
	</tr>
	<tr id="seckillDateSec">
	</tr>
	<tr>
		<td>产品数量：</td>
		<td><input type="text" name="count" id="count" value="1" /><span
			style="color: red;">*必须填写</span>
		</td>
	</tr>
	<tr>
		<td colspan="2" style="text-align: center;"><button
				style="width: 100px; height: 20px;" onclick="addSecKillTimeButton()">添加秒杀</button>
		</td>
	</tr>
	<tr>
		<td style="height: 150px">秒杀数据列表：</td>
		<td style="height: 150px" id="seckill_item"></td>
	</tr>
	<tr>
		<td>手机验证信息：</td>
		<td><input type="text" name="validateMsg" id="validateMsg" />
		</td>
	</tr>
	<tr>
		<td></td>
		<td style="text-align: center;"><button
				onclick="releaseSeckill()">确认发布</button>
			<button onclick="closedReleaseSeckill()">取消</button>
		</td>

	</tr>
</table>

